//
//  MineTableViewController.m
//  赵彬旭
//
//  Created by lanou3g on 16/1/15.
//  Copyright © 2016年 赵彬旭. All rights reserved.
//

#import "MineTableViewController.h"
#import "MineOneTableViewCell.h"
#import "MineDescTableViewController.h"
#import "DisCoverViewController.h"
#import "DisCoverThreeLoginViewController.h"
#import "DisCoverYouJIManager.h"

@interface MineTableViewController ()

@property(nonatomic,strong)UIView *picView;

@property(nonatomic,strong)UIButton * headViewButton;

@property(nonatomic,strong)UILabel * nameLabel;

@property(nonatomic,strong)UILabel * idLabel;

@property(nonatomic,strong)UIButton * frandListButton;

@property(nonatomic,strong)UIButton * whoSeeMeButton;



@end

@implementation MineTableViewController

NSString *identifierMineOne = @"mineidentifiercell";


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self.tableView registerNib:[UINib nibWithNibName:@"MineOneTableViewCell" bundle:nil] forCellReuseIdentifier:identifierMineOne];
    

    self.picView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,self.view.frame.size.height/3 + 40 )];
   // _picView.backgroundColor = [UIColor cyanColor];
    self.headViewButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _headViewButton.frame = CGRectMake(self.view.frame.size.width/2, _picView.frame.size.height/2 - 40 , 120, 120);
    _headViewButton.center = CGPointMake(self.view.frame.size.width/2, _picView.frame.size.height/2 - 70);
    _headViewButton.backgroundColor = [UIColor orangeColor];
    _headViewButton.layer.cornerRadius = 60;
    _headViewButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"UMS_account_tap_white.jpg"]];
    _headViewButton.layer.masksToBounds = YES;
    [_headViewButton addTarget:self action:@selector(headButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2,_picView.frame.size.height/2 - 10, 200, 30)];
    _nameLabel.textAlignment = NSTextAlignmentCenter;
    _nameLabel.center = CGPointMake(self.view.frame.size.width/2, _picView.frame.size.height/2 + 20);
    //_nameLabel.backgroundColor = [UIColor grayColor];
    _nameLabel.text = @"昵称";
    
    
    self.idLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2, _picView.frame.size.height - 20, 200, 20)];
    _idLabel.center = CGPointMake(self.view.frame.size.width/2, _picView.frame.size.height - 80);
   // _idLabel.backgroundColor = [UIColor blueColor];
    _idLabel.textAlignment = NSTextAlignmentCenter;
    //_idLabel.text = @"384654656";
    
    self.frandListButton = [UIButton buttonWithType:UIButtonTypeSystem];
    
    //_frandListButton.backgroundColor = [UIColor redColor];
    
    _frandListButton.frame = CGRectMake(0, 0, 120, 50);
    
    _frandListButton.center = CGPointMake(self.view.frame.size.width/2 -100, _picView.frame.size.height/3 *2 + 60);
    
    [_frandListButton setTitle:@"好友列表" forState:UIControlStateNormal];
    
    _frandListButton.titleLabel.font = [UIFont systemFontOfSize:20];
    
    
    
    self.whoSeeMeButton = [UIButton buttonWithType:UIButtonTypeSystem];
    
   // _whoSeeMeButton.backgroundColor = [UIColor redColor];
    
    _whoSeeMeButton.frame = CGRectMake(0, 0, 120, 50);
    
    _whoSeeMeButton.center = CGPointMake(self.view.frame.size.width/2 +100, _picView.frame.size.height/3 *2 + 60);
    
    [_whoSeeMeButton setTitle:@"谁看过我" forState:UIControlStateNormal];
    
    _whoSeeMeButton.titleLabel.font = [UIFont systemFontOfSize:20];
    
    
    
    
    
    
    [_picView addSubview:_whoSeeMeButton];
    
    [_picView addSubview:_frandListButton];
    
    [_picView addSubview:_headViewButton];
    
    [_picView addSubview:_nameLabel];
    
    [_picView addSubview:_idLabel];
    
    self.tableView.tableHeaderView = _picView;
    
    
    if ([_setrr  isEqualToString: @"remm"]) {
        
        
        [_frandListButton removeFromSuperview];
        
        [_whoSeeMeButton removeFromSuperview];
        
       
        UIImage *buttonImage = [UIImage  imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:_headViewString]]];
        UIImage *stretchableButtonImage = [buttonImage  stretchableImageWithLeftCapWidth:12  topCapHeight:0];
        [_headViewButton setBackgroundImage:stretchableButtonImage  forState:UIControlStateNormal];
        
        
        //_headViewButton.contentMode = UIViewContentModeScaleAspectFit;
        
        
        
        
        _nameLabel.text = _nameLabelStr;
        
        _idLabel.text = _idLabelStr;
        
        
        
        
        
    }
    
  
    
    
}



-(void)viewWillAppear:(BOOL)animated{
   // _nameLabel.backgroundColor = [UIColor grayColor];
   // _headViewButton.backgroundColor = [UIColor redColor];

    
    if ([_setrr  isEqualToString: @"remm"]) {
        
        _nameLabel.text = _nameLabelStr;
        
        _idLabel.text = _idLabelStr;
        
    }else{
    
    
    
    _nameLabel.text = [DisCoverYouJIManager shareDisCoverYouJIManager].loginUserName;
    
    NSLog(@"-----%@",[DisCoverYouJIManager shareDisCoverYouJIManager].loginUserName);
    
    _headViewButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[DisCoverYouJIManager shareDisCoverYouJIManager].loginUserPic]]]];

    if (_nameLabel.text != nil ) {
        
         [_headViewButton removeTarget:self action:@selector(headButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    }
    

}



//-(void)passValue:(NSString *)value AndValuetwo:(NSString *)valuetwo{
//
//    _nameLabel.text = value;
//    
//    _headViewButton.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:valuetwo]]]];
//    
//}

    





-(void)headButtonAction:(UIButton*)sender{

    
    DisCoverThreeLoginViewController *disThree = [[DisCoverThreeLoginViewController alloc] init];
    
    
    
    [self.navigationController pushViewController:disThree animated:YES];
    


}









- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if ([_setrr  isEqualToString: @"remm"]) {
        
        return 1;
        
    }else{

    return 5;
    }
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MineOneTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifierMineOne forIndexPath:indexPath];
    
    cell.igView.image = [UIImage imageNamed:@"cinema"];
    
    cell.contentMode = UIViewContentModeScaleAspectFit;
    
    if ([_setrr  isEqualToString: @"remm"]) {
    
        cell.labelOne.text = @"她的帖子";
        
    
    
    }else{
    
    
    
    if (indexPath.row == 0) {
        
        cell.labelOne.text = @"我的帖子" ;
        cell.labelOne.font = [UIFont systemFontOfSize:20];
        cell.labelOne.textAlignment = NSTextAlignmentLeft;
        
        
    }else if(indexPath.row == 1){
    
        
        cell.labelOne.text = @"收藏" ;
        cell.labelOne.font = [UIFont systemFontOfSize:20];
        cell.labelOne.textAlignment = NSTextAlignmentLeft;
        
        
    }else if(indexPath.row == 2){
        
        cell.labelOne.text = @"设置";
        cell.labelOne.font = [UIFont systemFontOfSize:20];
        cell.labelOne.textAlignment = NSTextAlignmentLeft;
        
        
    }else if(indexPath.row == 3){
        
        
        cell.labelOne.text = @"帮助";
        cell.labelOne.font = [UIFont systemFontOfSize:20];
        cell.labelOne.textAlignment = NSTextAlignmentLeft;
        
      
    
    }else if(indexPath.row == 4){
        
        cell.labelOne.text = @"退出账号";
        cell.labelOne.font = [UIFont systemFontOfSize:20];
        cell.labelOne.textAlignment = NSTextAlignmentLeft;
        
        
    }
        
    }
    
    return cell;
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{


    return 60;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    
    if ([_setrr  isEqualToString: @"remm"]) {
        
        DisCoverViewController *discovVC = [[DisCoverViewController alloc] init];
        
        discovVC.xiangqingID = _idLabelStr;
        
        discovVC.navName = _nameLabelStr;
        
        
        
        [self.navigationController pushViewController:discovVC animated:YES];
        
        
    
    }else{
    
    
    MineDescTableViewController *mineTable = [[MineDescTableViewController alloc]init];
    
    mineTable.minecelllist = indexPath.row;
    
    
    [self.navigationController pushViewController:mineTable animated:YES];


}

}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
